home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PASCAL / 0187.ZIP / TWINKLE.PAS < prev    next >
Pascal/Delphi Source File  |  1985-01-20  |  2KB  |  106 lines

  1. (*
  2.  * twinkle
  3.  * randomly fill the screen with
  4.  * '*' and then randomly remove them
  5.  *)
  6.  
  7. program twinkle(output);
  8.  
  9. const
  10.    scrsize = 1920;      (* number of points on the screen *)
  11.  
  12.    xmax    = 79;        (* maximum x location (0 -> 79) *)
  13.    ymax    = 23;        (* maximum y location *)
  14.  
  15. type
  16.    pos = record
  17.       xloc : 0..xmax;
  18.       yloc : 0..ymax
  19.    end;
  20.  
  21.    index = 1..scrsize;
  22.  
  23. var
  24.    screen : array[index] of pos;
  25.  
  26.    (*
  27.     * init
  28.     * do a primitive clear screen,
  29.     * then init the screen array
  30.     *)
  31.  
  32. procedure init;
  33.  
  34. var
  35.    scrindex : integer;  (* index into screen array *)
  36.    x : 0..xmax;
  37.    y : 0..ymax;
  38.  
  39. begin
  40.    (* do a simple clear screen *)
  41.    for y := 0 to ymax do
  42.       writeln;
  43.  
  44.    randomize;
  45.  
  46.    scrindex := 1;
  47.    for x := 0 to xmax do
  48.       for y := 0 to ymax do
  49.       begin
  50.          screen[scrindex].xloc := x;
  51.          screen[scrindex].yloc := y;
  52.          scrindex := scrindex + 1
  53.       end
  54. end;  (* init *)
  55.  
  56. (*
  57.  * shuffle
  58.  * shuffle the screen index
  59.  *)
  60.  
  61. procedure shuffle;
  62.  
  63. var
  64.    i : index;
  65.    tmp : pos;
  66.    rnd : index;
  67.  
  68. begin
  69.    for i := 1 to scrsize do
  70.    begin
  71.       rnd := random(scrsize) + 1;
  72.       tmp := screen[rnd];
  73.       screen[rnd] := screen[i];
  74.       screen[i] := tmp
  75.    end
  76. end;  (* shuffle *)
  77.  
  78. (*
  79.  * fill
  80.  * fill up the screen with a character
  81.  *)
  82.  
  83. procedure fill(ch:char);
  84.  
  85. var
  86.    i : index;
  87.  
  88. begin
  89.    for i := 1 to scrsize do
  90.    begin
  91.       gotoxy(screen[i].xloc,screen[i].yloc);
  92.       write(ch)
  93.    end;
  94. end;  (* fill *)
  95.  
  96.  
  97.     (* main  *)
  98.  
  99. begin
  100.    init;
  101.    shuffle;
  102.    fill ('*');
  103.    shuffle;
  104.    fill (' ')
  105. end.  (* twinkle *)
  106.